
import axios from 'axios';
 
const TIMEOUT = 10000; // 默认超时时间为10秒
 
// 创建一个axios实例
const instance = axios.create({
  baseURL:  "/api", // api的base_url import.meta.env.VUE_APP_BASE_API 也可以直接写
  timeout: TIMEOUT, // 请求超时时间
  headers: {
    'Content-Type': 'application/json;charset=UTF-8'
  }
});

// 暂不考虑过滤器

export default {
    get(url:string, params = {}, timeout = TIMEOUT) {
      return instance.get(url, {
        params,
        timeout
      });
    },
    post(url:string, data = {}, timeout = TIMEOUT) {
      return instance.post(url, data, {
        timeout
      });
    },
    put(url:string, data = {}, timeout = TIMEOUT) {
      return instance.put(url, data, {
        timeout
      });
    },
    delete(url:string, params = {}, timeout = TIMEOUT) {
      return instance.delete(url, {
        params,
        timeout
      });
    }
  };